﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AFCEPF.Samples.WebSamples.Concepts
{
    public partial class View_QueryStringEmitter : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// Redirects to the result page with the TextBox values in the QueryString.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnRedirect_Click(object sender, EventArgs e)
        {
            // Url de la page cible.
            string targetUrl    = "~/Concepts/View_QueryStringReceiver.aspx";
            
            // Constitution du QueryString.
            string queryString  = buildQueryString();

            // Constitution de l'URL avec le QueryString.
            string completeUrl = string.Format("{0}{1}",
                                               targetUrl,
                                               queryString);

            // Redirection vers la page de résultats.
            Response.Redirect(completeUrl);

        }

        /// <summary>
        /// Builds the QueryString to be appended to the target page's URL.
        /// </summary>
        /// <returns>the QueryString to be appended to the target page's URL.</returns>
        private string buildQueryString()
        {
            string result;

            result = string.Format("?Name={0}&FirstName={1}",
                                   txtName.Text,
                                   txtFirstName.Text);

            return result;
        }
    }
}